package com.syni.mdd.sjb.common.datatreaure.service.impl.databank;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.syni.mdd.sjb.common.component.mybatis.dxshapp.entity.DankClientGroup;
import com.syni.mdd.sjb.common.component.mybatis.dxshapp.entity.DankGroup;
import com.syni.mdd.sjb.common.component.utils.common.utils.*;
import com.syni.mdd.sjb.common.datatreaure.constants.Constants;
import com.syni.mdd.sjb.common.datatreaure.constants.ResultMsg;
import com.syni.mdd.sjb.common.datatreaure.entity.vo.rp.dataBankClient.*;
import com.syni.mdd.sjb.common.datatreaure.entity.vo.rp.databBankCommon.StatisticsDataRpVo;
import com.syni.mdd.sjb.common.datatreaure.entity.vo.rq.BaseRqVo;
import com.syni.mdd.sjb.common.datatreaure.entity.vo.rq.dataBankClient.ChangeUserGroupRqVo;
import com.syni.mdd.sjb.common.datatreaure.entity.vo.rq.dataBankClient.ClientDataRqVo;
import com.syni.mdd.sjb.common.datatreaure.mapstruct.ClientDataCovertBasic;
import com.syni.mdd.sjb.common.datatreaure.service.DankClientGroupService;
import com.syni.mdd.sjb.common.datatreaure.service.DankGroupService;
import com.syni.mdd.sjb.common.datatreaure.service.UserService;
import com.syni.mdd.sjb.common.datatreaure.service.databank.DataBankClientService;
import com.syni.mdd.sjb.common.datatreaure.utils.CDPUtils;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.*;

@Service
public class DataBankClientServiceImpl implements DataBankClientService {

    private final Logger log = LoggerFactory.getLogger(getClass());


    @Autowired
    DankClientGroupService dankClientGroupService;
    @Autowired
    DankGroupService dankGroupService;
    @Autowired
    UserService userService;

    //客户全部
    private final String clientNumAndValue = "/cdp/cdp-web-api/customer-value/customer-value-total";         //客户数量与价值
    private final String activeLevelUrl = "/cdp/cdp-web-api/customer-value/active-customer-type";            //活跃水平分布请求地址
    private final String activeTimeUrl = "/cdp/cdp-web-api/customer-value/active-customer-time-total";       //活跃时间段分布
    private final String clientAttributeUrl = "/cdp/cdp-web-api/customer-value/customer-attribute-total";    //客户属性

    //客户分群
    private final String clienGroupUrl = "/cdp/cdp-web-api/customer-value/customer-value-group-details";    //客户分群价值
    private final String clienValueUrl = "/cdp/cdp-web-api/customer-value/customer-value-details";          //客户价值与策略
    private final String consumptionUrl = "/cdp/cdp-web-api/customer-value/consumption-amount-total";       //消费金额分布
    private final String buyingUrl = "/cdp/cdp-web-api/customer-value/buying-pattern-total";                //购买分布

    @Override
    public Map<String, Object> getAllClientData(ClientDataRqVo clientDataRqVo) {
        ClientAllGroupRpVo clientAllGroupRpVo = new ClientAllGroupRpVo();
        clientAllGroupRpVo.setTotalUser(24).setTotalValue(11072D).setTotalYester(0).setPotenCustomer(22)
                .setPotenValue(7612D).setPotenYester(0).setVipNum(12).setVipValue(6228D).setVipYester(0).setCusNum(2)
                .setCusValue(3460D).setCusYester(0).setSuggestion("专业术语解析");
        clientAllGroupRpVo.setSuggestion("总用户数=参与商户活动人数+浏览商户小程序+消费用户\n" +
                "潜客数=用户中未产生消费的用户\n" +
                "客客数=用户中已产生消费的用户\n" +
                "会员数=用户中成为商户会员店的用户");

        List<StatisticsDataRpVo> statisticsDataRpVoList = commonPart();
        clientAllGroupRpVo.setStatisticsDataRpVo(statisticsDataRpVoList);
        return ResultMapHelper.success(clientAllGroupRpVo, ResultMsg.HAND_SUCCESS);
    }

    @Override
    public Map<String, Object> getAllClientDataOfficial(ClientDataRqVo clientDataRqVo) {
        String accountId = userService.getAccountIdByUserMap(clientDataRqVo.getUserId());
        log.info("accountId:{}",accountId);
        if (accountId.isEmpty()) {
            return ResultMapHelper.success(new ClientAllGroupRpVo(), ResultMsg.HAND_SUCCESS);
        }
        ClientAllGroupRpVo clientAllGroupRpVo = new ClientAllGroupRpVo();
        Map<String, Object> paramsMap = new HashMap<>();
        paramsMap.put("accountId", accountId);
        Map<String, Object> resultMap = CDPUtils.commonCall(clientNumAndValue, paramsMap);
        if (ResultMapHelper.isSuccess(resultMap)) {
            ClientParamRpVo clientParamRpVo = JSON.parseObject(JSON.toJSONString(resultMap.get("data")), ClientParamRpVo.class);
            clientAllGroupRpVo = ClientDataCovertBasic.INSTANCE.toConvertVo(clientParamRpVo);
        }
        paramsMap.put("type", clientDataRqVo.getType());
        log.info("paramsMap",paramsMap);
        List<StatisticsDataRpVo> groupAllData = commonPartOffical(paramsMap);
        clientAllGroupRpVo.setStatisticsDataRpVo(groupAllData);
        return ResultMapHelper.success(clientAllGroupRpVo, ResultMsg.HAND_SUCCESS);
    }

    @Override
    public Map<String, Object> getTypicalData(ClientDataRqVo clientDataRqVo) {
        ClientTypicalRpVo clientTypicalRpVo = new ClientTypicalRpVo();
        String type = clientDataRqVo.getType();
        String userTypeName = null;
        switch (type){
            case "1": userTypeName = "全部客户";break;
            case "2": userTypeName = "典型客户";break;
            case "3": userTypeName = "高消费";break;
            case "4": userTypeName = "流失中";break;
            case "5": userTypeName = "潜力顾客";break;
            case "6": userTypeName = "低消费";break;
            case "7": userTypeName = "可发展";break;
            case "8": userTypeName = "活动积极";break;
            case "9": userTypeName = "活动潜水";break;
            case "10": userTypeName = "活动敏感";break;
            case "11": userTypeName = "活动无感";break;
        }
        clientTypicalRpVo.setUserTypeName(userTypeName);
        clientTypicalRpVo.setSuggestion("典型用户：\n" +
                "目标用户：高RFM值客户；\n" +
                "主要用户：80%的客户，消费用户中的m值在10%-90%的用户\n" +
                "显示标签\n" +
                "用户的主要年龄区间\n" +
                "用户的主要地区\n" +
                "此商店的类别属性\n" +
                "占比：\n" +
                "典型用户的总基于总用户数的占比\n" +
                "客户价值水平：\n" +
                "此类用户中，45-55%置信区间");

        List<StatisticsDataRpVo.DataDetail> yonghushuData = new ArrayList<>();
        StatisticsDataRpVo.DataDetail BINTU1 = new StatisticsDataRpVo.DataDetail("潜力客户", null, null, 30D, "#5AD8A6", new ArrayList<>(Arrays.asList("最新产生30", "天产生153", "次消费", "共计消费666元")));
        StatisticsDataRpVo.DataDetail BINTU2 = new StatisticsDataRpVo.DataDetail("低频客户", null, null, 42D,  "#F6BD16", new ArrayList<>(Arrays.asList("最新产生30", "天产生153", "次消费", "共计消费666元")));
        StatisticsDataRpVo.DataDetail BINTU3 = new StatisticsDataRpVo.DataDetail("vip客户", null, null, 12D, "#5D7092", new ArrayList<>(Arrays.asList("最新产生30", "天产生153", "次消费", "共计消费666元")));
        StatisticsDataRpVo.DataDetail BINTU4 = new StatisticsDataRpVo.DataDetail("常客", null, null, 16D, "#E8684A", new ArrayList<>(Arrays.asList("最新产生30", "天产生153", "次消费", "共计消费666元")));
        List<StatisticsDataRpVo.SuggestionDetail> suggestionDetailList1 = new ArrayList<>();
        StatisticsDataRpVo.SuggestionDetail yonghushuSuggestion1 = new StatisticsDataRpVo.SuggestionDetail("低频顾客的消费频次可以通过定向发放一组限时优惠券来提高，通过低门槛券或无门槛券吸引顾客复购，提高顾客对店铺的印象分，转化为常客。","低门槛券或无门槛","https://mpsaas.syni.com/MTMS/thirdParty/shLogin?type=01-gift&token=");
        StatisticsDataRpVo.SuggestionDetail yonghushuSuggestion2 = new StatisticsDataRpVo.SuggestionDetail("不妨针对低频顾客设置营销活动，配合大额券或多次代金券组合，激活顾客购买欲，加深顾客对店铺的印象，转化为常客。","顾客对店铺的","https://mpsaas.syni.com/MTMS/thirdParty/shLogin?type=01-temp&token=");
        suggestionDetailList1.add(yonghushuSuggestion1);suggestionDetailList1.add(yonghushuSuggestion2);
        BINTU2.setRemark(suggestionDetailList1);

        List<StatisticsDataRpVo.SuggestionDetail> suggestionDetailList2 = new ArrayList<>();
        StatisticsDataRpVo.SuggestionDetail yonghushuSuggestion3 = new StatisticsDataRpVo.SuggestionDetail("潜力顾客是具有消费力的老顾客，针对客单价较高的潜力顾客，可以定向提供VIP服务（如专人客服、上新提醒、专属优惠）等，唤醒老顾客复购。","唤醒老","syni://customerGroup?type=1");
        StatisticsDataRpVo.SuggestionDetail yonghushuSuggestion4 = new StatisticsDataRpVo.SuggestionDetail("潜力顾客具有一定的消费力水平，建议对这部分顾客定向发布营销活动，配合老顾客专属店铺服务，重新激活顾客消费，鼓励复购。","务，重新激活顾客消费","https://mpsaas.syni.com/MTMS/thirdParty/shLogin?type=01-temp&token=");
        suggestionDetailList2.add(yonghushuSuggestion3);suggestionDetailList2.add(yonghushuSuggestion4);
        BINTU1.setRemark(suggestionDetailList2);

        List<StatisticsDataRpVo.SuggestionDetail> suggestionDetailList3 = new ArrayList<>();
        StatisticsDataRpVo.SuggestionDetail yonghushuSuggestion5 = new StatisticsDataRpVo.SuggestionDetail("常客的消费频率较高，可以通过发放有门槛消费券，鼓励顾客提升消费水平，提高店铺客单价。","顾客提升消","https://mpsaas.syni.com/MTMS/thirdParty/shLogin?type=01-gift&token=");
        StatisticsDataRpVo.SuggestionDetail yonghushuSuggestion6 = new StatisticsDataRpVo.SuggestionDetail("不妨将常客购买频率较高的商品组合捆绑销售，在迎合常客购买需求的同时，鼓励顾客囤货或拼单，提升客单价","购买需求的同时","syni://manage");
        suggestionDetailList3.add(yonghushuSuggestion5);suggestionDetailList3.add(yonghushuSuggestion6);
        BINTU4.setRemark(suggestionDetailList3);

        List<StatisticsDataRpVo.SuggestionDetail> suggestionDetailList4 = new ArrayList<>();
        StatisticsDataRpVo.SuggestionDetail yonghushuSuggestion7 = new StatisticsDataRpVo.SuggestionDetail("VIP顾客消费力相对较强，不妨定向发放大额满减券，鼓励顾客再次消费","客再次消费","https://mpsaas.syni.com/MTMS/thirdParty/shLogin?type=01-gift&token=");
        StatisticsDataRpVo.SuggestionDetail yonghushuSuggestion8 = new StatisticsDataRpVo.SuggestionDetail("VIP顾客是店铺的重要营收来源，建议为这部分顾客提供专人客服、会员优惠、定期爆款秒杀等VIP服务","爆款秒杀等VIP","www.baidu.com");
        StatisticsDataRpVo.SuggestionDetail yonghushuSuggestion9 = new StatisticsDataRpVo.SuggestionDetail("VIP顾客消费力强，可以设置VIP专属活动，定向推送，配合无门槛券或爆款特价，活跃顾客，鼓励复购","配合无门槛券或爆款特价","www.baidu.com");
        suggestionDetailList4.add(yonghushuSuggestion7);suggestionDetailList4.add(yonghushuSuggestion8);suggestionDetailList4.add(yonghushuSuggestion9);
        BINTU3.setRemark(suggestionDetailList4);

        yonghushuData.add(BINTU1);
        yonghushuData.add(BINTU2);
        yonghushuData.add(BINTU3);
        yonghushuData.add(BINTU4);

        List<StatisticsDataRpVo.DataDetail> yingshouData = new ArrayList<>();
        StatisticsDataRpVo.DataDetail ZHEZHU1 = new StatisticsDataRpVo.DataDetail("类型A", null, 30D, null, "#5AD8A6", new ArrayList<>(Arrays.asList("客户量：55人", "客户量占比：60%", "产生营收：432元", "营收占比：15%", "累计占比：15%")));
        List<StatisticsDataRpVo.SuggestionDetail> ZHEZHU1DetailList = new ArrayList<>();
        StatisticsDataRpVo.SuggestionDetail ZHEZHU1Suggestion = new StatisticsDataRpVo.SuggestionDetail("类客户量占比为xx%，营收占比偏低，建议提高此类客户的客单价。",null,null);
        ZHEZHU1DetailList.add(ZHEZHU1Suggestion);
        ZHEZHU1.setRemark(ZHEZHU1DetailList);
        StatisticsDataRpVo.DataDetail ZHEZHU2 = new StatisticsDataRpVo.DataDetail("类型B", null, 15D, null,  "#F6BD16", new ArrayList<>(Arrays.asList("客户量：55人", "客户量占比：60%", "产生营收：432元", "营收占比：15%", "累计占比：15%")));
        List<StatisticsDataRpVo.SuggestionDetail> ZHEZHU2DetailList = new ArrayList<>();
        StatisticsDataRpVo.SuggestionDetail ZHEZHU2Suggestion = new StatisticsDataRpVo.SuggestionDetail("类客户量占比为xx%，营收占比偏低，建议提高此类客户的客单价。",null,null);
        ZHEZHU2DetailList.add(ZHEZHU2Suggestion);
        ZHEZHU2.setRemark(ZHEZHU2DetailList);
        StatisticsDataRpVo.DataDetail ZHEZHU3 = new StatisticsDataRpVo.DataDetail("类型C", null, 10D, null, "#5D7092", new ArrayList<>(Arrays.asList("客户量：55人", "客户量占比：60%", "产生营收：432元", "营收占比：15%", "累计占比：15%")));
        List<StatisticsDataRpVo.SuggestionDetail> ZHEZHU3DetailList = new ArrayList<>();
        StatisticsDataRpVo.SuggestionDetail ZHEZHU3Suggestion = new StatisticsDataRpVo.SuggestionDetail("类客户量占比为xx%，营收占比偏低，建议提高此类客户的客单价。",null,null);
        ZHEZHU3DetailList.add(ZHEZHU3Suggestion);
        ZHEZHU3.setRemark(ZHEZHU2DetailList);
        StatisticsDataRpVo.DataDetail ZHEZHU4 = new StatisticsDataRpVo.DataDetail("类型D", null, 5D, null, "#E8684A", new ArrayList<>(Arrays.asList("客户量：55人", "客户量占比：60%", "产生营收：432元", "营收占比：15%", "累计占比：15%")));
        List<StatisticsDataRpVo.SuggestionDetail> ZHEZHU4DetailList = new ArrayList<>();
        StatisticsDataRpVo.SuggestionDetail ZHEZHU4Suggestion = new StatisticsDataRpVo.SuggestionDetail("类客户量占比为xx%，营收占比偏低，建议提高此类客户的客单价。",null,null);
        ZHEZHU4DetailList.add(ZHEZHU4Suggestion);
        ZHEZHU4.setRemark(ZHEZHU2DetailList);
        yingshouData.add(ZHEZHU1);
        yingshouData.add(ZHEZHU2);
        yingshouData.add(ZHEZHU3);
        yingshouData.add(ZHEZHU4);

        List<StatisticsDataRpVo.TagExplain> YStagExplains = new ArrayList<>();
        StatisticsDataRpVo.TagExplain YSTAG1 = new StatisticsDataRpVo.TagExplain("类型A", "5AD8A6");
        StatisticsDataRpVo.TagExplain YSTAG2 = new StatisticsDataRpVo.TagExplain("类型B", "5AD8A6");
        StatisticsDataRpVo.TagExplain YSTAG3 = new StatisticsDataRpVo.TagExplain("类型C", "5AD8A6");
        StatisticsDataRpVo.TagExplain YSTAG4 = new StatisticsDataRpVo.TagExplain("类型D", "5AD8A6");
        YStagExplains.add(YSTAG1);
        YStagExplains.add(YSTAG2);
        YStagExplains.add(YSTAG3);
        YStagExplains.add(YSTAG4);

        List<StatisticsDataRpVo.GetDataWithTime> KHJZYCLData = new ArrayList<>();
        StatisticsDataRpVo.SuggestionDetail suggestionDetail = new StatisticsDataRpVo.SuggestionDetail("低频顾客的消费频次可以通过定向发放一组限时优惠券来提高，通过低门槛券或无门槛券吸引顾客复购，提高顾客对店铺的印象分，转化为常客。","提高顾客对店铺的印象分","www.baidu.com");
        StatisticsDataRpVo.GetDataWithTime yonghushu = new StatisticsDataRpVo.GetDataWithTime("用户数" ,suggestionDetail, null, 0, null, yonghushuData, new ArrayList<>(), new ArrayList<>());
        StatisticsDataRpVo.GetDataWithTime yingshou = new StatisticsDataRpVo.GetDataWithTime("营收", suggestionDetail, null, 3, null, yingshouData, new ArrayList<>(), YStagExplains);
        KHJZYCLData.add(yonghushu);
        KHJZYCLData.add(yingshou);


        List<StatisticsDataRpVo.DataDetail> zhengtaiData = new ArrayList<>();
        StatisticsDataRpVo.DataDetail ZHENGTAI1 = new StatisticsDataRpVo.DataDetail("100", null, 3D, 6D,  "#5AD8A6", new ArrayList<>(Arrays.asList("内容一", "第二行内容", "三三三三行内容")));
        StatisticsDataRpVo.DataDetail ZHENGTAI2 = new StatisticsDataRpVo.DataDetail("200", null, 5D, 8D,  "#5AD8A6", new ArrayList<>(Arrays.asList("内容一", "第二行内容", "三三三三行内容")));
        StatisticsDataRpVo.DataDetail ZHENGTAI3 = new StatisticsDataRpVo.DataDetail("300", null, 8D, 9D,  "#5AD8A6", new ArrayList<>(Arrays.asList("内容一", "第二行内容", "三三三三行内容")));
        StatisticsDataRpVo.DataDetail ZHENGTAI4 = new StatisticsDataRpVo.DataDetail("400", null, 20D, 18D,  "#5AD8A6", new ArrayList<>(Arrays.asList("内容一", "第二行内容", "三三三三行内容")));
        StatisticsDataRpVo.DataDetail ZHENGTAI5 = new StatisticsDataRpVo.DataDetail("500", null, 15D, 12D,  "#5AD8A6", new ArrayList<>(Arrays.asList("内容一", "第二行内容", "三三三三行内容")));
        StatisticsDataRpVo.DataDetail ZHENGTAI6 = new StatisticsDataRpVo.DataDetail("600", null, 5D, 7D,  "#5AD8A6", new ArrayList<>(Arrays.asList("内容一", "第二行内容", "三三三三行内容")));
        zhengtaiData.add(ZHENGTAI1);
        zhengtaiData.add(ZHENGTAI2);
        zhengtaiData.add(ZHENGTAI3);
        zhengtaiData.add(ZHENGTAI4);
        zhengtaiData.add(ZHENGTAI5);
        zhengtaiData.add(ZHENGTAI6);

        List<StatisticsDataRpVo.NormalData> normalData = new ArrayList<>();
        StatisticsDataRpVo.NormalData QUJIAN1 = new StatisticsDataRpVo.NormalData(220D, 20D, 320D, 20D, "#E8684A");
        QUJIAN1.setPopContent(new ArrayList<>(Arrays.asList("内容一", "第二行内容", "三三三三行内容")));
        StatisticsDataRpVo.NormalData QUJIAN2 = new StatisticsDataRpVo.NormalData(330D, 20D, 420D, 20D, "#5D7092");
        QUJIAN2.setPopContent(new ArrayList<>(Arrays.asList("内容一", "第二行内容", "三三三三行内容")));
        normalData.add(QUJIAN1);
        normalData.add(QUJIAN2);

        List<StatisticsDataRpVo.TagExplain> tagExplains = new ArrayList<>();
        StatisticsDataRpVo.TagExplain TAG1 = new StatisticsDataRpVo.TagExplain("店铺", "5AD8A6");
        StatisticsDataRpVo.TagExplain TAG2 = new StatisticsDataRpVo.TagExplain("行业均价", "5AD8A6");
        StatisticsDataRpVo.TagExplain TAG3 = new StatisticsDataRpVo.TagExplain("行业情况", "5AD8A6");
        StatisticsDataRpVo.TagExplain TAG4 = new StatisticsDataRpVo.TagExplain("店铺均价", "5AD8A6");
        tagExplains.add(TAG1);
        tagExplains.add(TAG2);
        tagExplains.add(TAG3);
        tagExplains.add(TAG4);

        List<StatisticsDataRpVo.GetDataWithTime> XFJEFBData = new ArrayList<>();
        StatisticsDataRpVo.GetDataWithTime ZHENGTAI = new StatisticsDataRpVo.GetDataWithTime(null, suggestionDetail, null, 4, "合计1000个订单，合计1000.22元", zhengtaiData, normalData, tagExplains);
        XFJEFBData.add(ZHENGTAI);


        List<StatisticsDataRpVo.DataDetail> goumaiData = new ArrayList<>();
        StatisticsDataRpVo.DataDetail ZUOTIAN1 = new StatisticsDataRpVo.DataDetail("01:00", null, null, 10D,  "#5AD8A6", new ArrayList<>(Arrays.asList("内容一", "第二行内容", "三三三三行内容")));
        StatisticsDataRpVo.DataDetail ZUOTIAN2 = new StatisticsDataRpVo.DataDetail("02:00", null, null, 10D,  "#5AD8A6", new ArrayList<>(Arrays.asList("内容一", "第二行内容", "三三三三行内容")));
        StatisticsDataRpVo.DataDetail ZUOTIAN3 = new StatisticsDataRpVo.DataDetail("03:00", null, null, 20D,  "#5AD8A6", new ArrayList<>(Arrays.asList("内容一", "第二行内容", "三三三三行内容")));
        StatisticsDataRpVo.DataDetail ZUOTIAN4 = new StatisticsDataRpVo.DataDetail("04:00", null, null, 30D, "#5AD8A6", new ArrayList<>(Arrays.asList("内容一", "第二行内容", "三三三三行内容")));
        StatisticsDataRpVo.DataDetail ZUOTIAN5 = new StatisticsDataRpVo.DataDetail("05:00", null, null, 40D,  "#5AD8A6", new ArrayList<>(Arrays.asList("内容一", "第二行内容", "三三三三行内容")));
        StatisticsDataRpVo.DataDetail ZUOTIAN6 = new StatisticsDataRpVo.DataDetail("06:00", null, null, 50D, "#5AD8A6", new ArrayList<>(Arrays.asList("内容一", "第二行内容", "三三三三行内容")));
        StatisticsDataRpVo.DataDetail ZUOTIAN7 = new StatisticsDataRpVo.DataDetail("07:00", null, null, 60D,  "#5AD8A6", new ArrayList<>(Arrays.asList("内容一", "第二行内容", "三三三三行内容")));
        goumaiData.add(ZUOTIAN1);
        goumaiData.add(ZUOTIAN2);
        goumaiData.add(ZUOTIAN3);
        goumaiData.add(ZUOTIAN4);
        goumaiData.add(ZUOTIAN5);
        goumaiData.add(ZUOTIAN6);
        goumaiData.add(ZUOTIAN7);

        List<StatisticsDataRpVo.TagExplain> GOUMAITAGData = new ArrayList<>();
        StatisticsDataRpVo.TagExplain GOUMAITAG1 = new StatisticsDataRpVo.TagExplain("店铺", "5AD8A6");
        StatisticsDataRpVo.TagExplain GOUMAITAG2 = new StatisticsDataRpVo.TagExplain("行业情况", "5AD8A6");
        GOUMAITAGData.add(GOUMAITAG1);
        GOUMAITAGData.add(GOUMAITAG2);

        List<StatisticsDataRpVo.GetDataWithTime> GMFBData = new ArrayList<>();
        StatisticsDataRpVo.GetDataWithTime GOUMAI = new StatisticsDataRpVo.GetDataWithTime("昨天", suggestionDetail, null, 2, null, zhengtaiData, new ArrayList<>(), GOUMAITAGData);
        GOUMAI.setYAxisType(1);
        StatisticsDataRpVo.GetDataWithTime GOUMA2 = new StatisticsDataRpVo.GetDataWithTime("7天内", suggestionDetail, null, 2, null, zhengtaiData, new ArrayList<>(), GOUMAITAGData);
        GOUMA2.setYAxisType(1);
        StatisticsDataRpVo.GetDataWithTime GOUMA3 = new StatisticsDataRpVo.GetDataWithTime("30天内", suggestionDetail, null, 2, null, zhengtaiData, new ArrayList<>(), GOUMAITAGData);
        GOUMA3.setYAxisType(1);
        StatisticsDataRpVo.GetDataWithTime GOUMA4 = new StatisticsDataRpVo.GetDataWithTime("半年内", suggestionDetail, null, 2, null, zhengtaiData, new ArrayList<>(), GOUMAITAGData);
        GOUMA4.setYAxisType(1);
        GMFBData.add(GOUMAI);
        GMFBData.add(GOUMA2);
        GMFBData.add(GOUMA3);
        GMFBData.add(GOUMA4);

        List<StatisticsDataRpVo.innerDataFirst> XFSJinnerDataFirstList = new ArrayList<>();
        StatisticsDataRpVo.innerDataFirst KHJZYCL = new StatisticsDataRpVo.innerDataFirst("客户价值与策略", "客户价值与策略", KHJZYCLData);
        StatisticsDataRpVo.innerDataFirst XFJEFB = new StatisticsDataRpVo.innerDataFirst("消费金额分布", "每笔消费金额分布", XFJEFBData);
        StatisticsDataRpVo.innerDataFirst GMFB = new StatisticsDataRpVo.innerDataFirst("购买分布", "购买分布", GMFBData);
        XFSJinnerDataFirstList.add(KHJZYCL);
        XFSJinnerDataFirstList.add(XFJEFB);
        XFSJinnerDataFirstList.add(GMFB);


        List<StatisticsDataRpVo> statisticsDataRpVoList = commonPart();
        StatisticsDataRpVo XFSJDATA = new StatisticsDataRpVo("消费数据", XFSJinnerDataFirstList);
        statisticsDataRpVoList.add(0, XFSJDATA);
        clientTypicalRpVo.setStatisticsDataRpVo(statisticsDataRpVoList);
        return ResultMapHelper.success(clientTypicalRpVo, ResultMsg.HAND_SUCCESS);
    }

    @Override
    public Map<String, Object> getTypicalDataOfficial(ClientDataRqVo clientDataRqVo) {
        String accountId = userService.getAccountIdByUserMap(clientDataRqVo.getUserId());
        if (accountId.isEmpty()) {
            return ResultMapHelper.success(new ClientAllGroupRpVo(), ResultMsg.HAND_SUCCESS);
        }

        log.info("accountId",accountId);

        ClientTypicalRpVo clientTypicalRpVo = new ClientTypicalRpVo();
        String type = clientDataRqVo.getType();
        String userTypeName = null;
        switch (type){
            case "1": userTypeName = "全部客户";break;
            case "2": userTypeName = "典型客户";break;
            case "3": userTypeName = "高消费";break;
            case "4": userTypeName = "流失中";break;
            case "5": userTypeName = "潜力顾客";break;
            case "6": userTypeName = "低消费";break;
            case "7": userTypeName = "可发展";break;
            case "8": userTypeName = "活动积极";break;
            case "9": userTypeName = "活动潜水";break;
            case "10": userTypeName = "活动敏感";break;
            case "11": userTypeName = "活动无感";break;
        }
        clientTypicalRpVo.setUserTypeName(userTypeName);
        clientTypicalRpVo.setSuggestion("典型用户：\n" +
                "·目标用户：高RFM值客户；\n" +
                "·主要用户：80%的客户，消费用户中的m值在10%-90%的用户\n" +
                "显示标签\n" +
                "用户的主要年龄区间\n" +
                "用户的主要地区\n" +
                "此商店的类别属性\n" +
                "·占比：\n" +
                "典型用户的总基于总用户数的占比\n" +
                "·客户价值水平：\n" +
                "此类用户中，45-55%置信区间");

        Map<String, Object> paramsMap = new HashMap<>();
        paramsMap.put("accountId", accountId);
        paramsMap.put("type", clientDataRqVo.getType());
        Map<String, Object> resultMap = CDPUtils.commonCall(clienGroupUrl, paramsMap);
        if (ResultMapHelper.isSuccess(resultMap)) {
            GroupParamRpVo groupParamRpVo = JSON.parseObject(JSON.toJSONString(resultMap.get("data")), GroupParamRpVo.class);
            clientTypicalRpVo = ClientDataCovertBasic.INSTANCE.covertGroupParam(groupParamRpVo);
            List<GroupParamRpVo.TagDetail> tagList = groupParamRpVo.getTagList();
            List<String> userTagList = new ArrayList<>();
            for(GroupParamRpVo.TagDetail t : tagList){
                userTagList.add(t.getTagName());
            }
            clientTypicalRpVo.setUserTag(userTagList);
        }
//        paramsMap.put("type", clientDataRqVo.getType());
        log.info("paramsMap",paramsMap);
        List<StatisticsDataRpVo.innerDataFirst> XFSJinnerDataFirstList = new ArrayList<>();
        //客户价值与策略
        Map<String, Object> clientValueMap = CDPUtils.commonCall(clienValueUrl, paramsMap);
        StatisticsDataRpVo.innerDataFirst KHJZYCL = clientValuePart(clientValueMap);
        //消费金额分布
        Map<String, Object> consumptionMap = CDPUtils.commonCall(consumptionUrl, paramsMap);
        StatisticsDataRpVo.innerDataFirst XFJEFB = consumptionPart(consumptionMap);
        //购买分布
        List<Map<String,Object>> dataList = new ArrayList<>();
        //昨天数据
        paramsMap.put("totalDimension", Constants.CDP_DAY_YESTERDAY);
        dataList.add(CDPUtils.commonCall(buyingUrl, paramsMap));
        //七天内数据
        paramsMap.put("totalDimension", Constants.CDP_DAY_SERVEN);
        dataList.add(CDPUtils.commonCall(buyingUrl, paramsMap));
        //30天内
        paramsMap.put("totalDimension", Constants.CDP_DAY_THIRTY);
        dataList.add(CDPUtils.commonCall(buyingUrl, paramsMap));
        //半年内数据
        paramsMap.put("totalDimension", Constants.CDP_DAY_HALFYEAR);
        dataList.add(CDPUtils.commonCall(buyingUrl, paramsMap));
        StatisticsDataRpVo.innerDataFirst GMFB = buyingPart(dataList);

        XFSJinnerDataFirstList.add(KHJZYCL);
        XFSJinnerDataFirstList.add(XFJEFB);
        XFSJinnerDataFirstList.add(GMFB);

        paramsMap.remove("totalDimension");
        List<StatisticsDataRpVo> statisticsDataRpVoList = commonPartOffical(paramsMap);
        StatisticsDataRpVo XFSJDATA = new StatisticsDataRpVo("消费数据", XFSJinnerDataFirstList);
        statisticsDataRpVoList.add(0, XFSJDATA);
        clientTypicalRpVo.setStatisticsDataRpVo(statisticsDataRpVoList);
        return ResultMapHelper.success(clientTypicalRpVo, ResultMsg.HAND_SUCCESS);
    }

    //购买分布
    public StatisticsDataRpVo.innerDataFirst buyingPart(List<Map<String, Object>> dataList) {
        List<StatisticsDataRpVo.GetDataWithTime> GMFBData = new ArrayList<>();  //带时间数据
        //标签解释
        List<StatisticsDataRpVo.TagExplain> GOUMAITAGData = new ArrayList<>();
        StatisticsDataRpVo.TagExplain GOUMAITAG1 = new StatisticsDataRpVo.TagExplain("店铺", "5AD8A6");
        StatisticsDataRpVo.TagExplain GOUMAITAG2 = new StatisticsDataRpVo.TagExplain("行业情况", "5AD8A6");
        GOUMAITAGData.add(GOUMAITAG1);
        GOUMAITAGData.add(GOUMAITAG2);

        if(dataList.size() != 0){
            Integer storeTotalQuantity = 0;
            Integer industryTotalQuantity = 0;
            Double maxBuy = 0d;
            List<String> titleList = new ArrayList<>(Arrays.asList("昨天","7天内","30天内","半年内"));
            Map<Double,String> suggestMap = new HashMap<>();
            for(Map<String,Object> m : dataList){
                List<StatisticsDataRpVo.DataDetail> goumaiData = new ArrayList<>();
                String dataTitle ="";
                StatisticsDataRpVo.SuggestionDetail remark = new StatisticsDataRpVo.SuggestionDetail();
                if(ResultMapHelper.isSuccess(m)){
                    List<BuyingRpVo> buyingRpVoList = JSON.parseArray(JSON.toJSONString(m.get("data")), BuyingRpVo.class);
                    for(BuyingRpVo b : buyingRpVoList){
                        storeTotalQuantity += (b.getStoreQuantity() == null?0:b.getStoreQuantity());
                        industryTotalQuantity += (b.getIndustryQuantity() == null?0:b.getStoreQuantity());
                    }
                    for(BuyingRpVo b : buyingRpVoList){
                        Integer inStoreQuantity = b.getStoreQuantity() == null?0:b.getStoreQuantity();
                        Integer inIndustryQuantity = b.getIndustryQuantity() == null?0:b.getStoreQuantity();

                        dataTitle =  b.getTime();

                        String title = titleList.get(0);
                        if(StringUtils.equals(title,"昨天")){
                            int length = dataTitle.length();
                            if(length == 1){
                                dataTitle = "0"+ dataTitle + ":00";
                            }else if(length == 2){
                                dataTitle = dataTitle + ":00";
                            }
                        }else if(StringUtils.equals(title,"7天内") || StringUtils.equals(title,"30天内") ){
                            Date titleDate = DateTimeUtils.converStringToDate(dataTitle);
                            dataTitle = DateTimeUtils.converDateToString(titleDate,DateTimeUtils.DATE_PATTERN_DAY_10);
                        }else if(StringUtils.equals(title,"半年内")){
                            dataTitle = dataTitle.substring(dataTitle.indexOf("-")+1) + "月";
                        }

                        Double nowRatio = ArithUtil.div(inStoreQuantity, storeTotalQuantity, 2);
                        if(maxBuy<nowRatio){
                            maxBuy = nowRatio;
                            suggestMap.put(maxBuy,dataTitle);
                        }
                        List<String> popContent = new ArrayList<>();
                        popContent.add("店铺："+ ArithUtil.mul(ArithUtil.div(inStoreQuantity,storeTotalQuantity,2),100) + "%");
                        popContent.add("行业情况："+ ArithUtil.mul(ArithUtil.div(inIndustryQuantity,industryTotalQuantity,2),100) + "%");
                        StatisticsDataRpVo.DataDetail ZUOTIAN = new StatisticsDataRpVo.DataDetail(dataTitle, null, ArithUtil.mul(ArithUtil.div(inStoreQuantity,storeTotalQuantity,2),100), ArithUtil.mul(ArithUtil.div(inIndustryQuantity,industryTotalQuantity,2),100),  "#5AD8A6", popContent);
                        goumaiData.add(ZUOTIAN);
                    }
                }
                if(maxBuy != 0) {
                    remark.setText(suggestMap.get(maxBuy) + "的购买最高，为" + ArithUtil.mul(maxBuy, 100) + "%");
                }
                StatisticsDataRpVo.GetDataWithTime GOUMAI = new StatisticsDataRpVo.GetDataWithTime(titleList.get(0), remark, null, 2, null, goumaiData, new ArrayList<>(), GOUMAITAGData);
                GOUMAI.setYAxisType(1);
                GMFBData.add(GOUMAI);
                titleList.remove(0);
                suggestMap = new HashMap<>();
                maxBuy = 0d;
            }
        }

        StatisticsDataRpVo.innerDataFirst GMFB = new StatisticsDataRpVo.innerDataFirst("购买分布", "购买分布", GMFBData);
        return GMFB;
    }

    //消费金额分布
    public StatisticsDataRpVo.innerDataFirst  consumptionPart(Map<String, Object> dataMap) {
        List<StatisticsDataRpVo.DataDetail> zhengtaiData = new ArrayList<>();  //具体数据
        List<StatisticsDataRpVo.NormalData> normalData = new ArrayList<>();    //区间数据
        List<StatisticsDataRpVo.TagExplain> tagExplains = new ArrayList<>();   //标签数据
        StatisticsDataRpVo.SuggestionDetail remark = new StatisticsDataRpVo.SuggestionDetail();

        String summary = "合计0个订单，合计0元";
        if(ResultMapHelper.isSuccess(dataMap)){
            ConsumptionRpVo consumptionRpVo = JSON.parseObject(JSON.toJSONString(dataMap.get("data")), ConsumptionRpVo.class);
            summary = "合计" + consumptionRpVo.getOrderQuantity() + "个订单，合计" + consumptionRpVo.getTotalAmount() + "元";
            if(consumptionRpVo != null){
                List<ConsumptionRpVo.ConsumpData> list = consumptionRpVo.getList();
                Integer listSize = list.size();
                List<Integer> average = getAverage(listSize);
                if(listSize > 6){
                    Collections.sort(average);
                    for(Integer i : average){
                        ConsumptionRpVo.ConsumpData c = list.get(i);
                        StatisticsDataRpVo.DataDetail ZHENGTAI = new StatisticsDataRpVo.DataDetail(c.getMoney(), null, Double.parseDouble(c.getStoreQuantity()), Double.parseDouble(c.getIndustryQuantity()), "#5AD8A6", new ArrayList<>());
                        zhengtaiData.add(ZHENGTAI);
                    }
                }else{
                    for(ConsumptionRpVo.ConsumpData c : list){
                        StatisticsDataRpVo.DataDetail ZHENGTAI = new StatisticsDataRpVo.DataDetail(c.getMoney(), null, Double.parseDouble(c.getStoreQuantity()), Double.parseDouble(c.getIndustryQuantity()), "#5AD8A6", new ArrayList<>());
                        zhengtaiData.add(ZHENGTAI);
                    }
                }


                String storePrice = consumptionRpVo.getStorePrice();         //店铺价格区间
                String[] storePriceArray = storePrice.split("-");
                String industryPrice = consumptionRpVo.getIndustryPrice();   //行业价格区间
                String[] industryPriceArray = industryPrice.split("-");
                StatisticsDataRpVo.NormalData QUJIAN1 = null;
                StatisticsDataRpVo.NormalData QUJIAN2 = null;
                if(new ArrayList<>(Arrays.asList(storePriceArray)).size() == 1){
                    if(!storePriceArray[0].isEmpty()){
                        QUJIAN1 = new StatisticsDataRpVo.NormalData(Double.parseDouble(storePriceArray[0]), null, null, null, "#E8684A");
                    }
                }else if(new ArrayList<>(Arrays.asList(storePriceArray)).size() == 2){
                    if(!storePriceArray[0].isEmpty() && !storePriceArray[1].isEmpty()) {
                        QUJIAN1 = new StatisticsDataRpVo.NormalData(Double.parseDouble(storePriceArray[0]), null, Double.parseDouble(storePriceArray[1]), null, "#E8684A");
                    }
                }
                if(new ArrayList<>(Arrays.asList(industryPriceArray)).size() == 1){
                    if(!industryPriceArray[0].isEmpty()) {
                        QUJIAN2 = new StatisticsDataRpVo.NormalData(Double.parseDouble(industryPriceArray[0]), null, null, null, "#E8684A");
                    }
                }else if(new ArrayList<>(Arrays.asList(industryPriceArray)).size() == 2){
                    if(!industryPriceArray[0].isEmpty() && !industryPriceArray[1].isEmpty()) {
                        QUJIAN2 = new StatisticsDataRpVo.NormalData(Double.parseDouble(industryPriceArray[0]), null, Double.parseDouble(industryPriceArray[1]), null, "#E8684A");
                    }
                }
                if(storePrice!=null && !storePrice .isEmpty()){
                    QUJIAN1.setPopContent(new ArrayList<>(Arrays.asList("店铺价格区间", storePrice)));
                    normalData.add(QUJIAN1);
                }
                if(industryPrice != null  && !industryPrice .isEmpty()){
                    QUJIAN2.setPopContent(new ArrayList<>(Arrays.asList("行业价格区间", industryPrice)));
                    normalData.add(QUJIAN2);
                }
            }
            //TODO 分析结果
            remark.setText("行业均价高于店铺均价，不妨将常客购买频率较高的商品组合捆绑销售，在迎合常客购买需求的同时，鼓励顾客囤货或拼单，提升客单价。");
        }

        StatisticsDataRpVo.TagExplain TAG1 = new StatisticsDataRpVo.TagExplain("店铺", "5AD8A6");
        StatisticsDataRpVo.TagExplain TAG2 = new StatisticsDataRpVo.TagExplain("行业均价", "5AD8A6");
        StatisticsDataRpVo.TagExplain TAG3 = new StatisticsDataRpVo.TagExplain("行业情况", "5AD8A6");
        StatisticsDataRpVo.TagExplain TAG4 = new StatisticsDataRpVo.TagExplain("店铺均价", "5AD8A6");
        tagExplains.add(TAG1);
        tagExplains.add(TAG2);
        tagExplains.add(TAG3);
        tagExplains.add(TAG4);

        List<StatisticsDataRpVo.GetDataWithTime> XFJEFBData = new ArrayList<>();
        StatisticsDataRpVo.GetDataWithTime ZHENGTAI = new StatisticsDataRpVo.GetDataWithTime(null, remark, null, 4, summary, zhengtaiData, normalData, tagExplains);
        XFJEFBData.add(ZHENGTAI);

        StatisticsDataRpVo.innerDataFirst XFJEFB = new StatisticsDataRpVo.innerDataFirst("消费金额分布", "每笔消费金额分布", XFJEFBData);
        return XFJEFB;
    }

    public List<Integer> getAverage(Integer maxData){
        List<Integer> averageList = new ArrayList<>();
        Integer ave = maxData / 6;
        Integer init = 0 ;
        while(averageList.size() < 6){
            averageList.add(init);
            init = init + ave;
        }
        return averageList;
    }

    //客户价值与策略
    public StatisticsDataRpVo.innerDataFirst clientValuePart(Map<String, Object> dataMap) {
        List<StatisticsDataRpVo.DataDetail> yonghushuData = new ArrayList<>();     //用户数具体数据
        List<StatisticsDataRpVo.DataDetail> yingshouData = new ArrayList<>();      //营收具体数据
        List<StatisticsDataRpVo.TagExplain> YStagExplains = new ArrayList<>();     //营收标签
        List<StatisticsDataRpVo.SuggestionDetail> YSRemark = new ArrayList<>();    //营收分析结果
        Map<Integer,Map<String,Object>> maxMap = new HashMap<>();
        Map<String,Object> insideMap = new HashMap<>();
        insideMap.put("userRatio",0d);
        insideMap.put("revenueRatio",0d);
        insideMap.put("userType","低频客户");
        Integer maxDate = 0;
        maxMap.put(maxDate,insideMap);
        if(ResultMapHelper.isSuccess(dataMap)){
            List<ClientValueRpVo> clientValueRpVoList = JSON.parseArray(JSON.toJSONString(dataMap.get("data")), ClientValueRpVo.class);
            if(clientValueRpVoList.size() != 0){
                for(ClientValueRpVo c : clientValueRpVoList){
                    if(maxDate.compareTo(Integer.parseInt(c.getUserQuantity())) == -1){
                        maxDate = Integer.parseInt(c.getUserQuantity());
                        Map<String,Object> map = new HashMap<>();
                        map.put("userRatio",ArithUtil.mul(Double.parseDouble(c.getUserRatio()),100));
                        map.put("revenueRatio",ArithUtil.mul(Double.parseDouble(c.getRevenueRatio()),100));
                        map.put("userType",c.getUserType());
                        maxMap.put(maxDate, map);
                    }
                    //用户数PopContent
                    List<String> popContent = new ArrayList<>();
                    popContent.add("最近30天内产生"+ c.getStageQuantity() + "次消费");
                    popContent.add("共计消费" + c.getStageRevenue() +"元");
                    StatisticsDataRpVo.DataDetail BINTU = new StatisticsDataRpVo.DataDetail(c.getUserType(), ArithUtil.mul(Double.parseDouble(c.getUserRatio()),100) + "%", Double.parseDouble(c.getUserQuantity()), ArithUtil.mul(Double.parseDouble(c.getUserRatio()),100),  "#5AD8A6",popContent);

                    //营收PopContent
                    Double userRatio = Double.parseDouble(c.getUserRatio());         //客户量占比
                    Double revenueRatio = Double.parseDouble(c.getRevenueRatio());   //营收占比
                    Double totalRatio = Double.parseDouble(c.getTotalRatio());       //累计占比
                    List<String> YSPopContent = new ArrayList<>();
                    YSPopContent.add(c.getUserType());
                    YSPopContent.add("客户量："+c.getUserQuantity() + "人");
                    YSPopContent.add("客户量占比："+ArithUtil.mul(userRatio,100) + "%");
                    YSPopContent.add("产生营收："+c.getRevenue() + "元");
                    YSPopContent.add("营收占比："+ ArithUtil.mul(revenueRatio,100)+ "%");
                    YSPopContent.add("累计占比："+ ArithUtil.mul(totalRatio,100)+ "%");
                    StatisticsDataRpVo.DataDetail ZHEZHU = new StatisticsDataRpVo.DataDetail(c.getUserType(), null, Double.parseDouble(c.getUserQuantity()), ArithUtil.mul(totalRatio,100),  "#5AD8A6",YSPopContent);

                    List<StatisticsDataRpVo.SuggestionDetail> YHSRemark = new ArrayList<>();   //用户数分析结果
                    StatisticsDataRpVo.SuggestionDetail remarkOne = new StatisticsDataRpVo.SuggestionDetail();
                    StatisticsDataRpVo.SuggestionDetail remarkTwo = new StatisticsDataRpVo.SuggestionDetail();
                    StatisticsDataRpVo.SuggestionDetail remarkThree = new StatisticsDataRpVo.SuggestionDetail();
                    StatisticsDataRpVo.SuggestionDetail YSRemarkDetail = new StatisticsDataRpVo.SuggestionDetail();
                    if(StringUtils.equals(c.getUserType(),"低频客户")){
                        remarkOne.setText("低频顾客的消费频次可以通过定向发放一组限时优惠券来提高，通过低门槛券或无门槛券吸引顾客复购，提高顾客对店铺的印象分，转化为常客。");
                        remarkOne.setHighLightText("低门槛券或无门槛券");
                        YHSRemark.add(remarkOne);
                        remarkTwo.setText("不妨针对低频顾客设置营销活动，配合大额券或多次代金券组合，激活顾客购买欲，加深顾客对店铺的印象，转化为常客。");
                        YHSRemark.add(remarkTwo);
                        BINTU.setRemark(YHSRemark);
                    }else if(StringUtils.equals(c.getUserType(),"潜力客户")){
                        remarkOne.setText("潜力顾客是具有消费力的老顾客，针对客单价较高的潜力顾客，可以定向提供VIP服务（如专人客服、上新提醒、专属优惠）等，唤醒老顾客复购。");
                        YHSRemark.add(remarkOne);
                        remarkTwo.setText("潜力顾客具有一定的消费力水平，建议对这部分顾客定向发布营销活动，配合老顾客专属店铺服务，重新激活顾客消费，鼓励复购。");
                        YHSRemark.add(remarkTwo);
                        BINTU.setRemark(YHSRemark);
                    }else if(StringUtils.equals(c.getUserType(),"常客")){
                        remarkOne.setText("常客的消费频率较高，可以通过发放有门槛消费券，鼓励顾客提升消费水平，提高店铺客单价");
                        YHSRemark.add(remarkOne);
                        remarkTwo.setText("不妨将常客购买频率较高的商品组合捆绑销售，在迎合常客购买需求的同时，鼓励顾客囤货或拼单，提升客单价");
                        YHSRemark.add(remarkTwo);
                        BINTU.setRemark(YHSRemark);
                    }else if(StringUtils.equals(c.getUserType(),"vip客户")){
                        remarkOne.setText("VIP顾客消费力相对较强，不妨定向发放大额满减券，鼓励顾客再次消费");
                        YHSRemark.add(remarkOne);
                        remarkTwo.setText("VIP顾客是店铺的重要营收来源，建议为这部分顾客提供专人客服、会员优惠、定期爆款秒杀等VIP服务");
                        YHSRemark.add(remarkTwo);
                        remarkThree.setText("VIP顾客消费力强，可以设置VIP专属活动，定向推送，配合无门槛券或爆款特价，活跃顾客，鼓励复购");
                        YHSRemark.add(remarkThree);
                        BINTU.setRemark(YHSRemark);
                    }
                    if(userRatio.compareTo(revenueRatio) == 1){
                        YSRemarkDetail.setText(c.getUserType()+"占比为" + ArithUtil.mul(userRatio,100) + "%，营收占比偏低，建议提高此类客户的客单价。");
                    }else if(userRatio.compareTo(revenueRatio) == -1){
                        YSRemarkDetail.setText(c.getUserType()+"占比为" + ArithUtil.mul(userRatio,100) + "%，营收占比为" + ArithUtil.mul(revenueRatio,100) +"%，建议提高为此类用户提供vip服务。");
                    }
                    YSRemark.add(YSRemarkDetail);
                    ZHEZHU.setRemark(YSRemark);

                    yonghushuData.add(BINTU);
                    yingshouData.add(ZHEZHU);

                    StatisticsDataRpVo.TagExplain YSTAG = new StatisticsDataRpVo.TagExplain(c.getUserType(), "5AD8A6");
                    YStagExplains.add(YSTAG);
                }
            }
        }

        Map<String, Object> resultMaxMap = maxMap.get(maxDate);
        String maxUserType = String.valueOf(resultMaxMap.get("userType"));
        Double maxUserRatio = Double.parseDouble(resultMaxMap.get("userRatio").toString());
        Double maxRevenueRatio = Double.parseDouble(resultMaxMap.get("revenueRatio").toString());
        String YHSRemarkOut = null;
        String YSRemarkOut = null;
        if(maxUserRatio.compareTo(0d) != 0){
            if(StringUtils.equals(maxUserType,"低频客户")){
                YHSRemarkOut = "低频顾客的消费频次可以通过定向发放一组限时优惠券来提高，通过低门槛券或无门槛券吸引顾客复购，提高顾客对店铺的印象分，转化为常客。";
            }else if(StringUtils.equals(maxUserType,"潜力客户")){
                YHSRemarkOut = "潜力顾客是具有消费力的老顾客，针对客单价较高的潜力顾客，可以定向提供VIP服务（如专人客服、上新提醒、专属优惠）等，唤醒老顾客复购。";
            }else if(StringUtils.equals(maxUserType,"常客")){
                YHSRemarkOut = "常客的消费频率较高，可以通过发放有门槛消费券，鼓励顾客提升消费水平，提高店铺客单价";
            }else if(StringUtils.equals(maxUserType,"vip客户")){
                YHSRemarkOut = "VIP顾客消费力相对较强，不妨定向发放大额满减券，鼓励顾客再次消费";
            }

        }
        if(maxRevenueRatio.compareTo(0d) != 0) {
            if (maxUserRatio.compareTo(maxRevenueRatio) == 1) {
                YSRemarkOut = maxUserType + "客户量占比为" + maxUserRatio + "%，营收占比偏低，建议提高此类客户的客单价。";
            } else if (maxUserRatio.compareTo(maxRevenueRatio) == -1) {
                YSRemarkOut = maxUserType + "客户量占比为" + maxUserRatio + "%，营收占比为" + maxRevenueRatio + "，建议提高为此类用户提供vip服务。";
            }
        }

        List<StatisticsDataRpVo.GetDataWithTime> KHJZYCLData = new ArrayList<>();
        StatisticsDataRpVo.GetDataWithTime yonghushu = new StatisticsDataRpVo.GetDataWithTime("用户数", new StatisticsDataRpVo.SuggestionDetail(YHSRemarkOut,null,null), null, 0, null, yonghushuData, new ArrayList<>(), new ArrayList<>());
        StatisticsDataRpVo.GetDataWithTime yingshou = new StatisticsDataRpVo.GetDataWithTime("营收", new StatisticsDataRpVo.SuggestionDetail(YSRemarkOut,null,null), null, 3, null, yingshouData, new ArrayList<>(), YStagExplains);
        KHJZYCLData.add(yonghushu);
        KHJZYCLData.add(yingshou);

        StatisticsDataRpVo.innerDataFirst KHJZYCL = new StatisticsDataRpVo.innerDataFirst("客户价值与策略", "客户价值与策略", KHJZYCLData);
        return KHJZYCL;
    }



    //活跃水平分布具体数据
    public StatisticsDataRpVo.innerDataFirst activeLevelPart(Map<String, Object> dataMap) {
        Integer totalUserQuantity = 0;
        Double highActiveNum = 0d;Double lowActiveNum = 0d;
        Double noActiveNum = 0d;Double lossNum = 0d;Double addedNum = 0d;
        Double dataRatio = 0d;
        List<StatisticsDataRpVo.DataDetail> HYSPFBData = new ArrayList<>();
        if(ResultMapHelper.isSuccess(dataMap)){
            List<ActiveLevelRpVo> activeLevelData = JSON.parseArray(JSON.toJSONString(dataMap.get("data")), ActiveLevelRpVo.class);
            if(activeLevelData.size() != 0){
                //处理数据
                for(ActiveLevelRpVo a :activeLevelData){
                    totalUserQuantity += a.getUserQuantity();
                }
                StatisticsDataRpVo.DataDetail HYBINT = null;
                for(ActiveLevelRpVo a :activeLevelData){
                    if(StringUtils.equals(a.getUserType(),"高活跃客户")){
                        highActiveNum = ArithUtil.div(a.getUserQuantity(),totalUserQuantity,2);
                        dataRatio = highActiveNum;
                    }else if(StringUtils.equals(a.getUserType(),"低活跃客户")){
                        lowActiveNum = ArithUtil.div(a.getUserQuantity(),totalUserQuantity,2);
                        dataRatio = lowActiveNum;
                    }else if(StringUtils.equals(a.getUserType(),"不活跃客户")){
                        noActiveNum = ArithUtil.div(a.getUserQuantity(),totalUserQuantity,2);
                        dataRatio = noActiveNum;
                    }else if(StringUtils.equals(a.getUserType(),"流失客户")){
                        lossNum = ArithUtil.div(a.getUserQuantity(),totalUserQuantity,2);
                        dataRatio = lossNum;
                    }else if(StringUtils.equals(a.getUserType(),"新增客户")){
                        addedNum = ArithUtil.div(a.getUserQuantity(),totalUserQuantity,2);
                        dataRatio = addedNum;
                    }
                    HYBINT = new StatisticsDataRpVo.DataDetail(a.getUserType(), a.getUserQuantity() +"人, "+ ArithUtil.mul(dataRatio,100) + "%", a.getUserQuantity().doubleValue(), ArithUtil.mul(dataRatio,100),  "#5AD8A6", null);
                    HYSPFBData.add(HYBINT);
                }
            }
        }


        String suggestion ="·高活跃：7天内访问过店铺页面\n" + "·低活跃：最近7天未访问过店铺页面\n" +
                "·不活跃：最近30天未访问过店铺页面\n" + "·流失：最近60天未访问过店铺页面\n" + "·新增用户：7天内首次访问店铺页面的用户";
        StatisticsDataRpVo.SuggestionDetail remark = null;
        if(highActiveNum.compareTo(0.40D) == 1 || new Double(ArithUtil.add(highActiveNum, lowActiveNum)).compareTo(0.70D) == 1){
            remark = new StatisticsDataRpVo.SuggestionDetail();
            remark.setText("用户相对活跃，店铺曝光度良好，请继续保持。建议定向派发优惠券促进消费，鼓励观望用户下单");
        }else if(noActiveNum.compareTo(0.40D) == 1 && (highActiveNum.compareTo(0.40D) == -1 || highActiveNum.compareTo(0.40D) == 0)){
            remark = new StatisticsDataRpVo.SuggestionDetail();
            remark.setText("用户活跃情况不理想，店铺曝光量可能不足；建议发布一个营销活动吸引用户到店，提升活跃度");
        }else if(lossNum.compareTo(0.40D) == 1 && (highActiveNum.compareTo(0.40D) == -1 || highActiveNum.compareTo(0.40D) == 0)){
            remark = new StatisticsDataRpVo.SuggestionDetail();
            remark.setText("用户活跃情况不理想，店铺曝光量可能不足；建议发布一个营销活动吸引用户到店，提升活跃度");
        }else if(new Double(ArithUtil.add(lossNum,noActiveNum)).compareTo(0.60D) == 1){
            remark = new StatisticsDataRpVo.SuggestionDetail();
            remark.setText("用户活跃情况不理想，店铺曝光量可能不足；建议发布一个营销活动吸引用户到店，提升活跃度");
        }else if(addedNum.compareTo(0.30D) == 1){
            remark = new StatisticsDataRpVo.SuggestionDetail();
            remark.setText("新增用户较多，店铺曝光明显，可能是近期活动或热门新品见效了。不妨乘胜追击，对新用户定向发放无门槛券，快速转化为有价值客户");
        }else{
            remark = new StatisticsDataRpVo.SuggestionDetail();
            remark.setText("暂无建议");
        }

        List<StatisticsDataRpVo.GetDataWithTime> HYSPFB = new ArrayList<>();
        StatisticsDataRpVo.GetDataWithTime HYSP = new StatisticsDataRpVo.GetDataWithTime(null, remark, suggestion, 0, 0, "人", null, 0, HYSPFBData, new ArrayList<>(), new ArrayList<>());
        HYSPFB.add(HYSP);

        StatisticsDataRpVo.innerDataFirst HYSPFBINNER = new StatisticsDataRpVo.innerDataFirst("活跃水平分布", "活跃水平分布", HYSPFB);
        return HYSPFBINNER;
    }

    //活跃时间段分布
    public StatisticsDataRpVo.innerDataFirst activeTimePart(List<Map<String, Object>> dataList) {
        List<StatisticsDataRpVo.DataDetail> HYSJDData = new ArrayList<>();         //详细数据
        List<StatisticsDataRpVo.GetDataWithTime> HYSJDFB = new ArrayList<>();      //带时间数据
        Double totalQuantity = 0d;
        StatisticsDataRpVo.SuggestionDetail remark = new StatisticsDataRpVo.SuggestionDetail();
        List<String> titleList = new ArrayList<>(Arrays.asList("昨天","7天内","30天内","半年内"));
        String dateTitle = titleList.get(0);
        Double bigRatio=0d;

        /*StatisticsDataRpVo.TagExplain TagExplain1 = new StatisticsDataRpVo.TagExplain("清晨 05:00~06:59","5AD8A6");
        StatisticsDataRpVo.TagExplain TagExplain2 = new StatisticsDataRpVo.TagExplain("早上 07:00~08:59","5AD8A6");
        StatisticsDataRpVo.TagExplain TagExplain3 = new StatisticsDataRpVo.TagExplain("上午 09:00~11:59","5AD8A6");
        StatisticsDataRpVo.TagExplain TagExplain4 = new StatisticsDataRpVo.TagExplain("中午 12:00~13:59","5AD8A6");
        StatisticsDataRpVo.TagExplain TagExplain5 = new StatisticsDataRpVo.TagExplain("下午 14:00~17:59","5AD8A6");
        StatisticsDataRpVo.TagExplain TagExplain6 = new StatisticsDataRpVo.TagExplain("傍晚 18:00~18:59","5AD8A6");
        StatisticsDataRpVo.TagExplain TagExplain7 = new StatisticsDataRpVo.TagExplain("晚上 19:00~23:59","5AD8A6");
        StatisticsDataRpVo.TagExplain TagExplain8 = new StatisticsDataRpVo.TagExplain("凌晨 03:00~04:59","5AD8A6");
        HYSJDTagExplain.add(TagExplain1);HYSJDTagExplain.add(TagExplain2);HYSJDTagExplain.add(TagExplain3);HYSJDTagExplain.add(TagExplain4);
        HYSJDTagExplain.add(TagExplain5);HYSJDTagExplain.add(TagExplain6);HYSJDTagExplain.add(TagExplain7);HYSJDTagExplain.add(TagExplain8);*/

        for(Map<String,Object> m : dataList){
            List<StatisticsDataRpVo.TagExplain> HYSJDTagExplain = new ArrayList<>();
            dateTitle = titleList.get(0);
            HYSJDData = new ArrayList<>();
            if(ResultMapHelper.isSuccess(m)){
                Map<String,Object> resultMap = JSON.parseObject(JSON.toJSONString(m.get("data")), Map.class);
                totalQuantity = Double.parseDouble(String.valueOf(resultMap.get("totalQuantity")));
                List<ActiveTimeRpVo> activeTimeData = JSON.parseArray(JSON.toJSONString(resultMap.get("list")), ActiveTimeRpVo.class);
                for(ActiveTimeRpVo a :activeTimeData){
                    List<String> popContentList = new ArrayList<>();
                    String dateStr = DateTimeUtils.converDateToString(DateTimeUtils.addDay(new Date(), -1), DateTimeUtils.DATE_PATTERN_DAY_13);
                    if(StringUtils.equals(dateTitle,"7天内")){
                        String s = DateTimeUtils.converDateToString(DateTimeUtils.addDay(new Date(), -7), DateTimeUtils.DATE_PATTERN_DAY_13);
                        dateStr = s + "~" +DateTimeUtils.converDateToString(new Date(),DateTimeUtils.DATE_PATTERN_DAY_13);
                    }else if(StringUtils.equals(dateTitle,"30天内")){
                        String s = DateTimeUtils.converDateToString(DateTimeUtils.addDay(new Date(), -30), DateTimeUtils.DATE_PATTERN_DAY_13);
                        dateStr = s + "~" +DateTimeUtils.converDateToString(new Date(),DateTimeUtils.DATE_PATTERN_DAY_13);
                    }else if(StringUtils.equals(dateTitle,"半年内")){
                        String s = DateTimeUtils.converDateToString(DateTimeUtils.addDay(new Date(), -180), DateTimeUtils.DATE_PATTERN_DAY_13);
                        dateStr = s + "~" +DateTimeUtils.converDateToString(new Date(),DateTimeUtils.DATE_PATTERN_DAY_13);
                    }
                    popContentList.add(dateStr);
                    popContentList.add("访问量：" + a.getAccessQuantity() + "人");
                    popContentList.add("占比：" + ArithUtil.mul(Double.parseDouble(a.getRatio()),100) + "%");
                    popContentList.add("累计占比：" + ArithUtil.mul(Double.parseDouble(a.getTotalRatio()),100) + "%");
                    String xTime = "";
                    String tagName = "";
                    switch (a.getTime()){
                        case "5" : xTime = "清晨";tagName ="清晨 05:00~06:59";break;
                        case "7" : xTime = "早上";tagName ="早上 07:00~08:59";break;
                        case "9" : xTime = "上午";tagName ="上午 09:00~11:59";break;
                        case "12" : xTime = "中午";tagName ="中午 12:00~13:59";break;
                        case "14" : xTime = "下午";tagName ="下午 14:00~17:59";break;
                        case "18" : xTime = "傍晚";tagName ="傍晚 18:00~18:59";break;
                        case "19" : xTime = "晚上";tagName ="晚上 19:00~23:59";break;
                        case "24" : xTime = "凌晨";tagName ="凌晨 03:00~04:59";break;
                    }
                    StatisticsDataRpVo.DataDetail HYZHEZHU = new StatisticsDataRpVo.DataDetail(xTime,null,a.getAccessQuantity().doubleValue(),ArithUtil.mul(Double.parseDouble(a.getTotalRatio()),100),"#5AD8A6",popContentList);
                    HYSJDData.add(HYZHEZHU);

                    StatisticsDataRpVo.TagExplain TagExplain = new StatisticsDataRpVo.TagExplain(tagName,"5AD8A6");
                    HYSJDTagExplain.add(TagExplain);

                    remark = new StatisticsDataRpVo.SuggestionDetail();
                    //分析结果
                    if(bigRatio.compareTo(Double.parseDouble(a.getRatio())) == -1){
                        bigRatio = Double.parseDouble(a.getRatio());
                    }
                    if(bigRatio.compareTo(0.50D) == 1){
                        remark.setText("用户活跃水平中等，建议对用户发放满减券，促使用户增加浏览时间并下单消费");
                    }else if(bigRatio.compareTo(0.30D) == 1){
                        remark.setText("用户活跃，店内产品对用户有吸引力，建议对停留时间长的用户定向发放无门槛券，鼓励用户下单消费");
                    }
                }
            }
            StatisticsDataRpVo.GetDataWithTime  HYSJD = new StatisticsDataRpVo.GetDataWithTime(dateTitle,remark,null,3,1,null,"合计" + totalQuantity.intValue() + "个访问量",0,HYSJDData,new ArrayList<>(),HYSJDTagExplain);
            titleList.remove(0);
            HYSJDFB.add(HYSJD);
        }


        StatisticsDataRpVo.innerDataFirst HYSJDINNER= new StatisticsDataRpVo.innerDataFirst("活跃时间段分布","活跃时间段分布",HYSJDFB);
        return HYSJDINNER;
    }

    //用户属性（性别分布、客户来源分布、新老客户分布）
    public List<StatisticsDataRpVo.innerDataFirst> customerAttributePart(Map<String,Object> dataMap) {
        List<StatisticsDataRpVo.DataDetail> XBFBData = new ArrayList<>();   //性别分布具体数据
        List<StatisticsDataRpVo.DataDetail> KHLYData = new ArrayList<>();   //客户来源具体数据
        List<StatisticsDataRpVo.DataDetail> KYFXData = new ArrayList<>();   //新老客户分布具体数据
        StatisticsDataRpVo.SuggestionDetail XBFBRemark = new StatisticsDataRpVo.SuggestionDetail();
        StatisticsDataRpVo.SuggestionDetail KHLYRemark = new StatisticsDataRpVo.SuggestionDetail();
        StatisticsDataRpVo.SuggestionDetail KYFXRemark = new StatisticsDataRpVo.SuggestionDetail();
        if(ResultMapHelper.isSuccess(dataMap)){
            Map<String,Object> resultMap = JSON.parseObject(JSON.toJSONString(dataMap.get("data")), Map.class);
            //性别分布数据
            Integer totalNum = 0;
            Double male = 0d;Double female = 0d;Double unkonw = 0d;Double dataRatio = 0d;
            List<GenderRpVo> genderList = JSON.parseArray(JSON.toJSONString(resultMap.get("genderList")), GenderRpVo.class);
            if(genderList.size() != 0){
                for(GenderRpVo g : genderList){
                    totalNum += g.getQuantity();
                }
                String dataTitle ="";
                for(GenderRpVo g : genderList){
                    if(StringUtils.equals(g.getGender(),"1")){
                        male = ArithUtil.div(g.getQuantity(),totalNum,2);
                        dataRatio = male;
                        dataTitle = "男";
                    }else if(StringUtils.equals(g.getGender(),"2")){
                        female = ArithUtil.div(g.getQuantity(),totalNum,2);
                        dataRatio = female;
                        dataTitle = "女";
                    }else if(StringUtils.equals(g.getGender(),"0")){
                        unkonw = ArithUtil.div(g.getQuantity(),totalNum,2);
                        dataRatio = unkonw;
                        dataTitle = "未知";
                    }
                    StatisticsDataRpVo.DataDetail XBBINT = new StatisticsDataRpVo.DataDetail(dataTitle,g.getQuantity() +"人,"+ ArithUtil.mul(dataRatio,100) + "%",g.getQuantity().doubleValue(),ArithUtil.mul(dataRatio,100),"#5AD8A6",null);
                    XBFBData.add(XBBINT);
                }
                Double differentValue = ArithUtil.sub(male, female);
                String sex = "男性";
                if(differentValue.compareTo(0D) == 1){  //男性大于女性
                    sex = "男性";
                }else if(differentValue.compareTo(0D) == -1){  //女性男性大于
                    sex = "女性";
                }
                if(new Double(ArithUtil.sub(0,differentValue)).compareTo(0.10D) ==1 ){
                    XBFBRemark.setText(sex +"用户更加关注本店，建议在店铺装修、上新时考虑这类用户的偏好");
                }else if(new Double(ArithUtil.sub(0,differentValue)).compareTo(0.10D) ==0 ){
                    XBFBRemark.setText(sex +"用户更加关注本店，建议在店铺装修、上新时考虑这类用户的偏好");
                }else if(new Double(ArithUtil.sub(0,differentValue)).compareTo(0.10D) == -1 ){
                    XBFBRemark.setText("关注本店的用户性别比例均衡，建议推广或营销时，结合产品和服务环境，精准选择目标人群，助力您的营收更胜一筹");
                }

            }

            //客户来源分布
            Integer KHLYNum = 0;
            Double mdd = 0d;Double minapp = 0d;Double wechat = 0d;
            Double KHLYRatio = 0d;
            SourceRpVo sr = new SourceRpVo();
            sr.setSource("无");
            sr.setDataRatio(0d);
            sr.setQuantity(0);
            Map<Integer,SourceRpVo> bigMap = new HashMap<>();
            Integer bigInteger = 0;
            bigMap.put(bigInteger,sr);
            List<SourceRpVo> sourceList = JSON.parseArray(JSON.toJSONString(resultMap.get("sourceList")), SourceRpVo.class);
            if(sourceList.size() != 0){
                for(SourceRpVo s : sourceList){
                    KHLYNum += s.getQuantity();
                }
                for(SourceRpVo s : sourceList){
                    s.setDataRatio(ArithUtil.div(s.getQuantity(),KHLYNum,2));
                    if(bigInteger.compareTo(s.getQuantity()) == -1){
                        bigInteger = s.getQuantity();
                        bigMap.put(bigInteger,s);
                    }
                    /*if(StringUtils.equals(s.getSource(),"觅东东")){
                        mdd = ArithUtil.div(s.getQuantity(),KHLYNum,2);
                        KHLYRatio = mdd;
                        if(bigInteger.compareTo(s.getQuantity()) == -1){
                            bigInteger = s.getQuantity();
                            bigMap.put(bigInteger,mdd+"_觅东东");
                        }
                    }else if(StringUtils.equals(s.getSource(),"小程序")){
                        minapp = ArithUtil.div(s.getQuantity(),KHLYNum,2);
                        KHLYRatio = minapp;
                        if(bigInteger.compareTo(s.getQuantity()) == -1){
                            bigInteger = s.getQuantity();
                            bigMap.put(bigInteger,minapp+"_小程序");
                        }
                    }else if(StringUtils.equals(s.getSource(),"企业微信")){
                        wechat = ArithUtil.div(s.getQuantity(),KHLYNum,2);
                        KHLYRatio = wechat;
                        if(bigInteger.compareTo(s.getQuantity()) == -1){
                            bigInteger = s.getQuantity();
                            bigMap.put(bigInteger,wechat+"_企业微信");
                        }
                    }*/
                    StatisticsDataRpVo.DataDetail KHBINT = new StatisticsDataRpVo.DataDetail(s.getSource(),s.getQuantity() +"人,"+ ArithUtil.mul(s.getDataRatio(),100) + "%",s.getQuantity().doubleValue(),ArithUtil.mul(s.getDataRatio(),100),"#5AD8A6",null);
                    KHLYData.add(KHBINT);
                }
                //客户来源分析结果
                if(!bigInteger.equals(0)){
                    SourceRpVo s = bigMap.get(bigInteger);
                    KHLYRemark.setText(s.getSource() + "渠道的客户数最多，占比最多。一共有" + bigInteger + "人，占总体客户数的" + ArithUtil.mul(s.getDataRatio(),100) +"%，不妨给"+s.getSource()+"用户定向发张券，吸引消费");
                }

            }

            //新老客户分布
            Double newRido = Double.parseDouble(resultMap.get("newRido").toString());                  //新客户占比
            String newUserQuantityStr = resultMap.get("newUserQuantity").toString();
            Integer newUserQuantity = null;
            if(newUserQuantityStr.isEmpty()){
                newUserQuantity = 0;
            }else{
                newUserQuantity = Integer.parseInt(newUserQuantityStr);   //新客户数
            }
            Double oldRido = Double.parseDouble(resultMap.get("oldRido").toString());                  //老客户占比
            String oldUserQuantityStr = resultMap.get("oldUserQuantity").toString();
            Integer oldUserQuantity = null;
            if(oldUserQuantityStr.isEmpty()){
                oldUserQuantity = 0;
            }else{
                oldUserQuantity = Integer.parseInt(oldUserQuantityStr);   //老客户数
            }
            StatisticsDataRpVo.DataDetail KYBINT1 = new StatisticsDataRpVo.DataDetail("新客户",newUserQuantity+"人,"+ArithUtil.mul(newRido,100)+"%",newUserQuantity.doubleValue(),ArithUtil.mul(newRido,100),"#5AD8A6",null);
            StatisticsDataRpVo.DataDetail KYBINT2 = new StatisticsDataRpVo.DataDetail("老客户",oldUserQuantity+"人,"+ArithUtil.mul(oldRido,100)+"%",oldUserQuantity.doubleValue(),ArithUtil.mul(oldRido,100),"#F6BD16",null);
            KYFXData.add(KYBINT1);KYFXData.add(KYBINT2);

            //新老客户分布分析结果
            if(newRido.compareTo(0.10D) == 1 || newRido.compareTo(0.10D) == 0){
                KYFXRemark.setText("老客户较多，建议保持品牌调性，开展长期粘性活动，保持老客户活性及粘性");
            }else if(newRido.compareTo(0.10D) == -1){
                KYFXRemark.setText("老客户较多，维护老客户能产生更大价值，开展长期活动增加用户粘性");
            }
        }

        //性别分布带时间数据
        List<StatisticsDataRpVo.GetDataWithTime> XBFBList = new ArrayList<>();
        StatisticsDataRpVo.GetDataWithTime  XBFB= new StatisticsDataRpVo.GetDataWithTime(null,XBFBRemark,null,0,1,"人",null,0,XBFBData,new ArrayList<>(),new ArrayList<>());
        XBFBList.add(XBFB);

        //客户来源带时间数据
        List<StatisticsDataRpVo.GetDataWithTime> KHLYList = new ArrayList<>();
        StatisticsDataRpVo.GetDataWithTime  KHLY= new StatisticsDataRpVo.GetDataWithTime(null,KHLYRemark,null,0,1,"人",null,0,KHLYData,new ArrayList<>(),new ArrayList<>());
        KHLYList.add(KHLY);

        //新老客户分布带时间数据
        List<StatisticsDataRpVo.GetDataWithTime> KYFXList = new ArrayList<>();
        StatisticsDataRpVo.GetDataWithTime KYFX = new StatisticsDataRpVo.GetDataWithTime(null,KYFXRemark,null,0,1,"人",null,0,KYFXData,new ArrayList<>(),new ArrayList<>());
        KYFXList.add(KYFX);

        List<StatisticsDataRpVo.innerDataFirst>  YHSXInnerData = new ArrayList<>();
        StatisticsDataRpVo.innerDataFirst XBFBINNER= new StatisticsDataRpVo.innerDataFirst("性别分布","性别分布",XBFBList);
        StatisticsDataRpVo.innerDataFirst KHLYINNER= new StatisticsDataRpVo.innerDataFirst("客户来源分布","客户来源分布",KHLYList);
        StatisticsDataRpVo.innerDataFirst KYFXINNER= new StatisticsDataRpVo.innerDataFirst("新老客户分布","新老客户分布",KYFXList);
        YHSXInnerData.add(XBFBINNER);YHSXInnerData.add(KHLYINNER);YHSXInnerData.add(KYFXINNER);
        return YHSXInnerData;
    }

    public List<StatisticsDataRpVo> commonPartOffical(Map<String,Object> paramsMap){
        /**活跃数据内容**/
        List<StatisticsDataRpVo.innerDataFirst> HYDataFirstList = new ArrayList<>();
        //活跃水平分布
        Map<String, Object> activeLevelMap = CDPUtils.commonCall(activeLevelUrl, paramsMap);
        StatisticsDataRpVo.innerDataFirst HYSPFBINNER = activeLevelPart(activeLevelMap);
        HYDataFirstList.add(HYSPFBINNER);

        //活跃时间段分布
        List<Map<String,Object>> dataList = new ArrayList<>();
        //昨天数据
        paramsMap.put("totalDimension", Constants.CDP_DAY_YESTERDAY);
        Map<String, Object> stringObjectMap = CDPUtils.commonCall(activeTimeUrl, paramsMap);
        dataList.add(stringObjectMap);
        //七天内数据
        paramsMap.put("totalDimension", Constants.CDP_DAY_SERVEN);
        dataList.add(CDPUtils.commonCall(activeTimeUrl, paramsMap));
        //30天内
        paramsMap.put("totalDimension", Constants.CDP_DAY_THIRTY);
        dataList.add(CDPUtils.commonCall(activeTimeUrl, paramsMap));
        //半年内数据
        paramsMap.put("totalDimension", Constants.CDP_DAY_HALFYEAR);
        dataList.add(CDPUtils.commonCall(activeTimeUrl, paramsMap));
        StatisticsDataRpVo.innerDataFirst HYSJDINNER = activeTimePart(dataList);
        HYDataFirstList.add(HYSJDINNER);

        /**用户属性内容**/
        paramsMap.remove("totalDimension");
        Map<String, Object> attributeMap = CDPUtils.commonCall(clientAttributeUrl, paramsMap);
        List<StatisticsDataRpVo.innerDataFirst> cutomerInnerList = customerAttributePart(attributeMap);

        /**全部模块图标数据**/
        List<StatisticsDataRpVo> groupAllData = new ArrayList<>();
        StatisticsDataRpVo activeData = new StatisticsDataRpVo("活跃数据",HYDataFirstList);
        StatisticsDataRpVo customerAttribute = new StatisticsDataRpVo("用户属性",cutomerInnerList);
        groupAllData.add(activeData);groupAllData.add(customerAttribute);
        return groupAllData;
    }

    public List<StatisticsDataRpVo> commonPart(){
        List<StatisticsDataRpVo> statisticsDataRpVoList = new ArrayList<>();
        //典型人群第二部分数据
        //活跃水平分布具体数据
        List<StatisticsDataRpVo.DataDetail> HYSPFBData = new ArrayList<>();
        StatisticsDataRpVo.DataDetail HYBINT1 = new StatisticsDataRpVo.DataDetail("新增客户","1人,4%",1D,4D,"#5AD8A6",null);
        StatisticsDataRpVo.DataDetail HYBINT2 = new StatisticsDataRpVo.DataDetail("流失客户","0,0",0D,0D,"#F6BD16",null);
        StatisticsDataRpVo.DataDetail HYBINT3 = new StatisticsDataRpVo.DataDetail("不活跃客户","17人,71%",17D,71D,"#5D7092",null);
        StatisticsDataRpVo.DataDetail HYBINT4 = new StatisticsDataRpVo.DataDetail("高活跃客户","2人,8%",2D,8D,"#E8684A",null);
        StatisticsDataRpVo.DataDetail HYBINT5 = new StatisticsDataRpVo.DataDetail("低活跃客户","4人,17%",4D,17D,"#E8684A",null);
        HYSPFBData.add(HYBINT1);HYSPFBData.add(HYBINT2);HYSPFBData.add(HYBINT3);
        HYSPFBData.add(HYBINT4);HYSPFBData.add(HYBINT5);

        //活跃时间段分布
        List<StatisticsDataRpVo.DataDetail> HYSJDData = new ArrayList<>();
        StatisticsDataRpVo.DataDetail HYZHEZHU1 = new StatisticsDataRpVo.DataDetail("清晨",null,30D,15D,"#5AD8A6",new ArrayList<>(Arrays.asList("8月5日","访问量：25人","占比：15%","累计占比：89%")));
        StatisticsDataRpVo.DataDetail HYZHEZHU2 = new StatisticsDataRpVo.DataDetail("早上",null,15D,18D,"#F6BD16",new ArrayList<>(Arrays.asList("8月5日","访问量：25人","占比：15%","累计占比：89%")));
        StatisticsDataRpVo.DataDetail HYZHEZHU3 = new StatisticsDataRpVo.DataDetail("上午",null,10D,12D,"#5D7092",new ArrayList<>(Arrays.asList("8月5日","访问量：25人","占比：15%","累计占比：89%")));
        StatisticsDataRpVo.DataDetail HYZHEZHU4 = new StatisticsDataRpVo.DataDetail("中午",null,5D,48D,"#E8684A",new ArrayList<>(Arrays.asList("8月5日","访问量：25人","占比：15%","累计占比：89%")));
        StatisticsDataRpVo.DataDetail HYZHEZHU5 = new StatisticsDataRpVo.DataDetail("下午",null,5D,8D,"#E8684A",new ArrayList<>(Arrays.asList("8月5日","访问量：25人","占比：15%","累计占比：89%")));
        StatisticsDataRpVo.DataDetail HYZHEZHU6 = new StatisticsDataRpVo.DataDetail("傍晚",null,5D,12D,"#E8684A",new ArrayList<>(Arrays.asList("8月5日","访问量：25人","占比：15%","累计占比：89%")));
        StatisticsDataRpVo.DataDetail HYZHEZHU7 = new StatisticsDataRpVo.DataDetail("晚上",null,5D,22D,"#E8684A",new ArrayList<>(Arrays.asList("8月5日","访问量：25人","占比：15%","累计占比：89%")));
        StatisticsDataRpVo.DataDetail HYZHEZHU8 = new StatisticsDataRpVo.DataDetail("凌晨",null,5D,33D,"#E8684A",new ArrayList<>(Arrays.asList("8月5日","访问量：25人","占比：15%","累计占比：89%")));
        HYSJDData.add(HYZHEZHU1);HYSJDData.add(HYZHEZHU2);HYSJDData.add(HYZHEZHU3);HYSJDData.add(HYZHEZHU4);
        HYSJDData.add(HYZHEZHU5);HYSJDData.add(HYZHEZHU6);HYSJDData.add(HYZHEZHU7);HYSJDData.add(HYZHEZHU8);

        List<StatisticsDataRpVo.TagExplain> HYSJDTagExplain = new ArrayList<>();
        StatisticsDataRpVo.TagExplain TagExplain1 = new StatisticsDataRpVo.TagExplain("清晨 05:00~06:59","5AD8A6");
        StatisticsDataRpVo.TagExplain TagExplain2 = new StatisticsDataRpVo.TagExplain("早上 07:00~08:59","5AD8A6");
        StatisticsDataRpVo.TagExplain TagExplain3 = new StatisticsDataRpVo.TagExplain("上午 09:00~11:59","5AD8A6");
        StatisticsDataRpVo.TagExplain TagExplain4 = new StatisticsDataRpVo.TagExplain("中午 12:00~13:59","5AD8A6");
        StatisticsDataRpVo.TagExplain TagExplain5 = new StatisticsDataRpVo.TagExplain("下午 14:00~17:59","5AD8A6");
        StatisticsDataRpVo.TagExplain TagExplain6 = new StatisticsDataRpVo.TagExplain("傍晚 18:00~18:59","5AD8A6");
        StatisticsDataRpVo.TagExplain TagExplain7 = new StatisticsDataRpVo.TagExplain("晚上 19:00~23:59","5AD8A6");
        StatisticsDataRpVo.TagExplain TagExplain8 = new StatisticsDataRpVo.TagExplain("凌晨 03:00~04:59","5AD8A6");
        HYSJDTagExplain.add(TagExplain8);HYSJDTagExplain.add(TagExplain7);HYSJDTagExplain.add(TagExplain6);HYSJDTagExplain.add(TagExplain5);
        HYSJDTagExplain.add(TagExplain4);HYSJDTagExplain.add(TagExplain3);HYSJDTagExplain.add(TagExplain2);HYSJDTagExplain.add(TagExplain1);

        List<StatisticsDataRpVo.GetDataWithTime> HYSPFB = new ArrayList<>();
        StatisticsDataRpVo.GetDataWithTime  HYSP= new StatisticsDataRpVo.GetDataWithTime(null,new StatisticsDataRpVo.SuggestionDetail("低活跃客户的人数最多，占比最大，共100人，占比为28%",null,null),"专业术语解析",0,0,"人",null,0,HYSPFBData,new ArrayList<>(),new ArrayList<>());
        HYSPFB.add(HYSP);

        List<StatisticsDataRpVo.GetDataWithTime> HYSJDFB = new ArrayList<>();
        StatisticsDataRpVo.GetDataWithTime  HYSJD1 = new StatisticsDataRpVo.GetDataWithTime("昨天",new StatisticsDataRpVo.SuggestionDetail("本月，傍晚的访问量最多，占比最多，共100个，占38%，建议此时间段前提前理货",null,null),"专业术语解析",3,1,null,"合计100个访问量",0,HYSJDData,new ArrayList<>(),HYSJDTagExplain);
        StatisticsDataRpVo.GetDataWithTime  HYSJD2 = new StatisticsDataRpVo.GetDataWithTime("7天内",new StatisticsDataRpVo.SuggestionDetail("本周，傍晚的访问量最多，占比最多，共100个，占38%",null,null),"专业术语解析",3,1,null,"合计100个访问量",0,HYSJDData,new ArrayList<>(),HYSJDTagExplain);
        StatisticsDataRpVo.GetDataWithTime  HYSJD3 = new StatisticsDataRpVo.GetDataWithTime("30天内",new StatisticsDataRpVo.SuggestionDetail("30天内，傍晚的访问量最多，占比最多，共100个，占38%，建议此时间段前提前理货",null,null),"专业术语解析",3,1,null,"合计100个访问量",0,HYSJDData,new ArrayList<>(),HYSJDTagExplain);
        StatisticsDataRpVo.GetDataWithTime  HYSJD4 = new StatisticsDataRpVo.GetDataWithTime("半年内",new StatisticsDataRpVo.SuggestionDetail("半年内，傍晚的访问量最多，占比最多，共100个，占38%，建议此时间段前提前理货",null,null),"专业术语解析",3,1,null,"合计100个访问量",0,HYSJDData,new ArrayList<>(),HYSJDTagExplain);
        HYSJDFB.add(HYSJD1);HYSJDFB.add(HYSJD2);
        HYSJDFB.add(HYSJD3);HYSJDFB.add(HYSJD4);

        List<StatisticsDataRpVo.innerDataFirst>  nullTitleinnerData = new ArrayList<>();
        StatisticsDataRpVo.innerDataFirst HYSPFBINNER= new StatisticsDataRpVo.innerDataFirst("活跃水平分布","活跃水平分布",HYSPFB);
        StatisticsDataRpVo.innerDataFirst HYSJDINNER= new StatisticsDataRpVo.innerDataFirst("活跃时间段分布","活跃时间段分布",HYSJDFB);
        nullTitleinnerData.add(HYSPFBINNER);nullTitleinnerData.add(HYSJDINNER);

        //典型人群第三部分数据
        //性别分布数据
        List<StatisticsDataRpVo.DataDetail> XBFBData = new ArrayList<>();
        StatisticsDataRpVo.DataDetail XBBINT1 = new StatisticsDataRpVo.DataDetail("女","100人,60%",100D,60D,"#5AD8A6",null);
        StatisticsDataRpVo.DataDetail XBBINT2 = new StatisticsDataRpVo.DataDetail("男","40D人,40%",40D,40D,"#F6BD16",null);
        XBFBData.add(XBBINT1);XBFBData.add(XBBINT2);

        //客户来源分布
        List<StatisticsDataRpVo.DataDetail> KHLYData = new ArrayList<>();
        StatisticsDataRpVo.DataDetail KHBINT1 = new StatisticsDataRpVo.DataDetail("小程序","20人,20%",20D,20D,"#5AD8A6",null);
        StatisticsDataRpVo.DataDetail KHBINT2 = new StatisticsDataRpVo.DataDetail("觅东东","40人,40%",40D,40D,"#F6BD16",null);
        StatisticsDataRpVo.DataDetail KHBINT3 = new StatisticsDataRpVo.DataDetail("企业微信","40人,20%",40D,40D,"#F6BD16",null);
        KHLYData.add(KHBINT1);KHLYData.add(KHBINT2);KHLYData.add(KHBINT3);

        //新老客户分布
        List<StatisticsDataRpVo.DataDetail> KYFXData = new ArrayList<>();
        StatisticsDataRpVo.DataDetail KYBINT1 = new StatisticsDataRpVo.DataDetail("新客户","60人,60%",null,25D,"#5AD8A6",null);
        StatisticsDataRpVo.DataDetail KYBINT2 = new StatisticsDataRpVo.DataDetail("老客户","40人,40%",null,75D,"#F6BD16",null);
        KYFXData.add(KYBINT1);KYFXData.add(KYBINT2);

        List<StatisticsDataRpVo.GetDataWithTime> XBFBList = new ArrayList<>();
        StatisticsDataRpVo.GetDataWithTime  XBFB= new StatisticsDataRpVo.GetDataWithTime(null,new StatisticsDataRpVo.SuggestionDetail("女性的客户数最多，占比最多。一共有100人，占总体客户数的80%",null,null),"专业术语解析",0,1,"人",null,0,XBFBData,new ArrayList<>(),new ArrayList<>());
        XBFBList.add(XBFB);

        List<StatisticsDataRpVo.GetDataWithTime> KHLYList = new ArrayList<>();
        StatisticsDataRpVo.GetDataWithTime  KHLY= new StatisticsDataRpVo.GetDataWithTime(null,new StatisticsDataRpVo.SuggestionDetail("觅东东渠道的客户数最多，占比最多。一共有100人，占总体客户数的80%",null,null),"专业术语解析",0,1,"人",null,0,KHLYData,new ArrayList<>(),new ArrayList<>());
        KHLYList.add(KHLY);

        List<StatisticsDataRpVo.GetDataWithTime> KYFXList = new ArrayList<>();
        StatisticsDataRpVo.GetDataWithTime KYFX = new StatisticsDataRpVo.GetDataWithTime(null,new StatisticsDataRpVo.SuggestionDetail("老客户较多，建议保持品牌调性，开展长期粘性活动，保持老客户活性及粘性。",null,null),"专业术语解析",0,1,"人",null,0,KYFXData,new ArrayList<>(),new ArrayList<>());
        KYFXList.add(KYFX);

        List<StatisticsDataRpVo.innerDataFirst>  YHSXInnerData = new ArrayList<>();
        StatisticsDataRpVo.innerDataFirst XBFBINNER= new StatisticsDataRpVo.innerDataFirst("性别分布","性别分布",XBFBList);
        StatisticsDataRpVo.innerDataFirst KHLYINNER= new StatisticsDataRpVo.innerDataFirst("客户来源分布","客户来源分布",KHLYList);
        StatisticsDataRpVo.innerDataFirst KYFXINNER= new StatisticsDataRpVo.innerDataFirst("新老客户分布","新老客户分布",KYFXList);
        YHSXInnerData.add(XBFBINNER);YHSXInnerData.add(KHLYINNER);YHSXInnerData.add(KYFXINNER);


        StatisticsDataRpVo NULLTITLE = new StatisticsDataRpVo("活跃数据",nullTitleinnerData);
        StatisticsDataRpVo YHSXDATA = new StatisticsDataRpVo("用户属性",YHSXInnerData);
        statisticsDataRpVoList.add(NULLTITLE);statisticsDataRpVoList.add(YHSXDATA);
        return statisticsDataRpVoList;
    }

    @Override
    public Map<String, Object> getUserGroup(BaseRqVo baseRqVo) {
        initClientData(baseRqVo.getUserId());
        Set<Integer> typeSet = new HashSet<>();
        //已选中标签
        List<DankClientGroup> selectedTag = dankClientGroupService.getSelectedTag(baseRqVo.getUserId(), Constants.COMMON_FLAG_TRUE_INT);
        List<UserGroupRpVo> userGroupRpVoList = BeanUtils.copyList(selectedTag,UserGroupRpVo.class);
        //用户全部标签
        List<DankClientGroup> dankClientGroupList = dankClientGroupService.findByUserId(baseRqVo.getUserId());
        List<UserGroupRpVo> allGroupList = BeanUtils.copyList(dankClientGroupList,UserGroupRpVo.class);
        for(UserGroupRpVo u : allGroupList){
            typeSet.add(u.getType());
        }

        if(typeSet.size() != 0){
            Map<Integer, DankGroup> dankGroupMap = dankGroupService.getGroupByIds(typeSet);
            for(UserGroupRpVo u : userGroupRpVoList){
                if(dankGroupMap.containsKey(u.getType())){
                    u.setGroupName(dankGroupMap.get(u.getType()).getGroupName());
                }
            }
            for(UserGroupRpVo u : allGroupList){
                if(dankGroupMap.containsKey(u.getType())){
                    u.setGroupName(dankGroupMap.get(u.getType()).getGroupName());
                }
            }
        }
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("myGroupList",userGroupRpVoList);
        resultMap.put("allGroupList",allGroupList);
        return ResultMapHelper.success(resultMap,ResultMsg.HAND_SUCCESS);
    }

    @Override
    public Map<String, Object> changeUserGroup(ChangeUserGroupRqVo changeUserGroupRqVo) {
        List<DankClientGroup> canEditData = dankClientGroupService.getCanEditData(changeUserGroupRqVo.getUserId());
        for(DankClientGroup d :canEditData){
            d.setIsSelect(Constants.COMMON_FLAG_FALSE_INT);
            d.setTagOrder(null);
        }
        dankClientGroupService.saveOrUpdateBatch(canEditData);
        Integer tagOrder = 1;
        List<String> selectedIds = JSON.parseArray(changeUserGroupRqVo.getUserGroupIds(), String.class);
        for(String s :selectedIds){
            DankClientGroup dankClientGroup = dankClientGroupService.getById(s);
            dankClientGroup.setIsSelect(Constants.COMMON_FLAG_TRUE_INT);
            dankClientGroup.setUpdateTime(LocalDateTime.now());
            dankClientGroup.setTagOrder(tagOrder);
            dankClientGroupService.saveOrUpdate(dankClientGroup);
            tagOrder++;
        }
        return ResultMapHelper.success(ResultMsg.HAND_SUCCESS);
    }

    @Override
    public void initClientData(Integer userId) {
        List<DankGroup> dankGroups = dankGroupService.getBaseMapper().selectList(new QueryWrapper<>());
        List<DankClientGroup> dankClientGroupList = dankClientGroupService.findByUserId(userId);
        if(!CollectionUtils.isNotEmpty(dankClientGroupList)){
            List<DankClientGroup> newDankClientGroupList = BeanUtils.copyListIgnore(dankGroups, DankClientGroup.class,"id","newTime");
            for(DankClientGroup d : newDankClientGroupList){
                d.setUserId(userId);
            }
            dankClientGroupService.saveBatch(newDankClientGroupList);
        }
    }


}
